package com.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.entity.UserEntity;

@Repository
public class UserDaoImpl extends GenericDaoImpl<UserEntity> implements UserDao {

	public UserEntity getUserById(int id) {
		return getById(UserEntity.class, id);
	}

	public List<UserEntity> getAllUser() {
		return getAll(UserEntity.class);
	}

	public UserEntity getUserByName(String name) {
		String hql = "From UserEntity where name =:name";
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery(hql);
		query.setParameter("name", name);
		return (UserEntity) query.uniqueResult();
	}

	public UserEntity getUserByEmail(String email) {
		String hql = "from UserEntity where emailAddress =:email";
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery(hql);
		query.setParameter("email", email);
		return (UserEntity) query.uniqueResult();
	}

}
